/*
package com.jml.config;

import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

// 配置授权中心信息   信息都是写死的
@Configuration
@EnableAuthorizationServer // 开启认证授权中心
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

	// accessToken有效期
	private int accessTokenValiditySeconds = 7200; // 两小时

	//可以获取授权码：
	// 			http://localhost:8080/oauth/authorize?response_type=code&client_id=client_1&redirect_uri=http://www.baidu.com
	//			回调地址的结果https://www.baidu.com/?code=Gjedue

	//获取access_token：
	// 			http://localhost:8080/oauth/token?grant_type=authorization_code&code=Gjedue&redirect_uri=http://www.baidu.com&scope=all
	//			返回结果{"access_token":"6df27cc2-6d88-4ce9-b901-3c7d5121b20b","token_type":"bearer","expires_in":7199,"scope":"all"}

	//密码模式就是使用用户名和密码获取Accesstoken，用户名密码来自userDetailsService方法中定义的
	//密码模式获取accesstioken：
	// 			调用接口 http://localhost:8080/oauth/token
	//			参数是grant_type、username、password、client_id、client_secret、scope

	//如果用户同时通过密码模式和授权码模式进行获取accesstoken，获取到accesstoken是一致的

	// 添加商户信息
	//这个方法就是配置appid ，appkey，回调地址，token的有效期
	public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
		// withClient appid
		clients.inMemory()
				//withClient里面是appid
				.withClient("client_1")
				//secret里面是appkey或者appsecrity
				.secret(passwordEncoder().encode("123456"))
				//回调地址
				.redirectUris("http://www.baidu.com")
				//授权的权限类型，这里分别为授权码模式,密码模式,刷新令牌
				.authorizedGrantTypes("authorization_code","password","refresh_token")
				//scopes表示范围
				.scopes("all")
				// accessToken有效期
				.accessTokenValiditySeconds(accessTokenValiditySeconds);
	}



	// 设置token类型,可以通过post和get方式获取
	public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
		endpoints.authenticationManager(authenticationManager())
				.allowedTokenEndpointRequestMethods(HttpMethod.GET,HttpMethod.POST);
		//刷新token需要加入下面两行
		endpoints.authenticationManager(authenticationManager());
		endpoints.userDetailsService(userDetailsService());
	}

	//
	@Override
	public void configure(AuthorizationServerSecurityConfigurer oauthServer) {
		// 允许表单认证
		oauthServer.allowFormAuthenticationForClients();
		// 允许check_token访问
		oauthServer.checkTokenAccess("permitAll()");
	}

	//获取授权Manager
	@Bean
	AuthenticationManager authenticationManager() {
		AuthenticationManager authenticationManager = new AuthenticationManager() {
			public Authentication authenticate(Authentication authentication) throws AuthenticationException {
				return daoAuhthenticationProvider().authenticate(authentication);
			}
		};
		return authenticationManager;
	}

	@Bean
	public AuthenticationProvider daoAuhthenticationProvider() {
		DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
		daoAuthenticationProvider.setUserDetailsService(userDetailsService());
		daoAuthenticationProvider.setHideUserNotFoundExceptions(false);
		daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());
		return daoAuthenticationProvider;
	}

	// 设置添加用户信息,正常应该从数据库中读取
	@Bean
	UserDetailsService userDetailsService() {
		InMemoryUserDetailsManager userDetailsService = new InMemoryUserDetailsManager();
		userDetailsService.createUser(User.withUsername("user_1").password(passwordEncoder().encode("123456"))
				.authorities("ROLE_USER").build());
		userDetailsService.createUser(User.withUsername("user_2").password(passwordEncoder().encode("1234567"))
				.authorities("ROLE_USER").build());
		return userDetailsService;
	}

	@Bean
	PasswordEncoder passwordEncoder() {
		// 加密方式
		PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
		return passwordEncoder;
	}
}
*/
